#ifndef					_WORLD_H_
#define					_WORLD_H_

#include "Common/Common.h"
#include <string>
#include <hash_map>
#include "Renderer/Renderer.h"

class b2World;
class CRenderer;
class b2Body;

class CWorld
{
public:
	~CWorld();

	struct stPair
	{
		b2Body*					pBody;
		irr::scene::ISceneNode* pNode;
		CATEGORY				cat;

		stPair()
		{
			pBody = 0;
			pNode = 0;
			cat	  = ACTION;
		}

		stPair(b2Body* pBody, irr::scene::ISceneNode* pNode, CATEGORY cat)
		{
			this->pBody = pBody;
			this->pNode = pNode;
			this->cat	= cat;
		}

		stPair& operator=(stPair pair)
		{
			this->pBody = pair.pBody;
			this->pNode = pair.pNode;
			this->cat	= pair.cat;
			return *this;
		}
	};

	int					Create(float timeStep = 0.00166667, int velIteration = 6, int posIteration = 2);
	int					Destroy();
	static CWorld*		Instance();

	int					AddDynSphere(std::string name, int nId, rVector3 pos, float radius, CATEGORY cat);
	void				Step();

	void				ClearQueryResult()	{	m_queryResult.clear(); }
	void				QueryResult(std::string title, float value)	
	{	
		m_queryResult[title] = value;
	}


private:
	CWorld(); 
	CWorld(const CWorld&);
	CWorld& operator=(const CWorld&);

	bool					m_bFlagCreate;

	static CWorld*			m_ptrInstance;

	CRenderer*				m_ptrRenderer;
	b2World*				m_ptrWorld;
	float					m_timeStep;
	int						m_velocityIterations;
	int						m_positionIteration;

	std::hash_map<std::string, stPair*>	m_bodyList;
	std::hash_map<std::string, float>	m_queryResult;
protected:
	void					t_ComputeForce(float& ret, float a, float b);	
};
	
#endif					//_WORLD_H_
